//
//  LGCollectionList_Controller.m
//  LoveTravel
//
//  Created by MS on 16-1-22.
//  Copyright (c) 2016年 Lemon. All rights reserved.
//

#import "LGCollectionList_Controller.h"
#import "LGProductDetail_Controller.h"
#import "UIBarButtonItem+Item.h"
#import "CollecListDataTool.h"
#import "Collection_List_View.h"
#import "CollecList_Frame.h"

@interface LGCollectionList_Controller ()<Collection_List_ViewDelegate>

@property (nonatomic,weak) Collection_List_View * collection_List_View;
@property (nonatomic,strong) CollecList_Frame * collecListFrame;
@property (nonatomic,weak) UILabel * titleLabel;

@end

@implementation LGCollectionList_Controller


-(CollecList_Frame *)collecListFrame
{
    if (_collecListFrame==nil) {
        _collecListFrame = [[CollecList_Frame alloc] init];
    }
    return _collecListFrame;
}

-(Collection_List_View *)collection_List_View
{
    if (_collection_List_View==nil) {
        Collection_List_View * listView = [[Collection_List_View alloc] initWithFrame:self.view.frame];
        _collection_List_View = listView;
        _collection_List_View.delegate = self;
        [self.view addSubview:listView];
    }
    return _collection_List_View;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];

    [self setUpnavigation];

    [self loadCollectionListData];

    //接收处理标题的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitleName:) name:@"SetTitle" object:nil];
}


-(void)loadCollectionListData
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [CollecListDataTool getCollectionListDataWithId:self.collection_Data.id_collection Succuss:^(CollecListModel *data) {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        self.collecListFrame.list = data;
        
        self.collection_List_View.collection_ListFrame = _collecListFrame;
        
    } failure:^(NSError *error) {
        
    }];
    
    
}

#pragma mark- 标题显示处理方法
-(void)setTitleName:(NSNotification *)note
{
    self.titleLabel.hidden =[note.userInfo[@"Hidden"] boolValue];
}

-(void)setUpnavigation
{
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"btn_back2"] andHighImage:[UIImage  imageNamed:@"btn_back2"] target:self action:@selector(backclick) forControlEvents:UIControlEventTouchUpInside];
                                             
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"btn_share_red"] andHighImage:[UIImage imageNamed:@"btn_share_red"] target:self action:@selector(shareClick) forControlEvents:UIControlEventTouchUpInside];
    
        UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 44)];
        titleLabel.hidden = YES;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor blackColor];
        titleLabel.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = titleLabel;
        titleLabel.text = self.collection_Data.title;
        self.titleLabel = titleLabel;
}

-(void)backclick
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)shareClick
{
    
}

-(void)collection_List_ViewDidCilck:(Collection_List_View *)collectList_View recomm:(RecommsData *)recomm index:(NSInteger)index
{
    LGProductDetail_Controller * vc = [[LGProductDetail_Controller alloc] init];
    vc.recomm_Data = recomm;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
